package com.gui.liner.link;

public class SingleLink<T> {

    private Node<T> head;

    private int size;

    public SingleLink() {
        this.head = new Node<>(null, null);
        this.size = 0;
    }


    public void add(T data) {
        Node<T> temp = head;
        if (temp.next == null) {
            temp.next = new Node<>(data, null);
            this.size ++;
            return;
        }
        while (temp.next != null) {
            temp = temp.next;
        }
        this.size ++;
        temp.next = new Node<>(data, null);
    }

    public T remove(int index) {
        return null;
    }

    public int size() {
        return this.size;
    }

    public void print() {
        Node<T> temp = head;
        while (temp.next != null) {
            System.out.println(temp.data);
            temp = temp.next;
        }
        System.out.println(temp.data);
    }


    private static class Node<T> {
        /**
         * 数据域
         */
        private T data;

        /**
         * 指针域
         */
        private Node<T> next;

        public Node(T data, Node<T> next) {
            this.data = data;
            this.next = next;
        }
    }
}
